﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CC98;
using CC98.Data;

namespace CC98.Metro.Data
{
    /// <summary>
    /// This session class store the current user session state
    /// Tracking authentication state
    /// Store operation history
    /// etc.
    /// </summary>
    public class UserSession
    {
        internal UserSession(CC98Client client)
        {
            if (client == null)
                throw new ArgumentNullException("client");
            this.Client = client;
            this.Client.AuthenticationStateChanged += ClientAuthenticationStateChanged;
        }

        public User User
        {
            get
            {
                return this.Client.CurrentUser;
            }
        }

        public CC98Client Client { get; private set; }

        protected virtual void OnAuthenticationStateChanged()
        {
            if (this.AuthenticationStateChanged != null)
                this.AuthenticationStateChanged(this, new EventArgs());
        }

        protected void ClientAuthenticationStateChanged(object sender, EventArgs e)
        {
            this.OnAuthenticationStateChanged();
        }


        public event EventHandler AuthenticationStateChanged;
    }
}
